<%--
  Created by IntelliJ IDEA.
  User: 隼
  Date: 2016/12/23
  Time: 1:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册界面</title>
    <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery-1.4.4.min.js">
    </script>
    <script type="text/javascript">

        function reloadImage(){
            document.getElementById("btn").disabled=true;
            document.getElementById("indentity").src="/sun/ramdonImg.action?ts="+new Date().getTime();
        }


        function verify(){
            alert("onclick");
            var cname=$("#userName").val();
            if(cname==null||cname==""){                      //name
                alert("用户名不能为空");
                return false;
            }
            var cpassword=$("#password").val();
            if(cpassword==null||cpassword==""){                //password
                alert("密码不能为空");
                return false;
            }
            //alert(cpassword);
            if(cpassword.length<6){                     //password>6
                alert("密码必须大于等于六位");
                return false;
            }
            var repassword=$("#repassword").val();
            //alert(repassword);
            if(repassword==null||repassword==""){                //password
                alert("请重复输入密码");
                return false;
            }
            if(repassword!=cpassword){							//repassword!=password
                alert("密码不一致");
                return false;
            }
            var csex=$("input[name='Sex']:checked").val();         //Sex
            if(csex==""||csex==null){
                alert("性别不能为空");
                return false;
            }else if(csex!="男"&&csex!="女"){
                alert("请输入人类的性别");
            }
            var year=$("#birthyear").val();
            var yue=$("#birthyue").val();
            var day=$("#birthday").val();

            //alert(isNaN(year));
            //alert(isNaN(yue));
            //alert(isNaN(day));
            var re =/^[1-9]+[0-9]*]*$/  ;
            if (!(re.test(year)&&re.test(yue)&&re.test(day))){                 //day is number
                alert("请输入正确的生日格式");
                return false;

            }

            var years=parseInt(year);
            var yues=parseInt(yue);
            var days=parseInt(day);
            var res=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

            if(years<=0){
                alert("年份输入错误，必须大于0");
                return false;
            }
            if(yues<=0||yues>=13){												//yue
                alert("月份输入错误");
                return false;
            }
            if(yues!=2){                                                          //day
                if(days<=0||days>res[yues-1]){
                    alert("天数有问题");
                    return false;
                }
            }else{
                var eryue;
                if((years%4==0)&&(year%100!=0)||year%400==0){
                    eryue=29;
                }else{
                    eryue=28;
                }
                if(days<=0||days>eryue){                            //二月
                    alert("二月天数有问题");
                    return false;
                }
            }

            var phone=$("#phonenb").val();
            if(phone==null||phone==""){
                alert("手机号不能为空");
                return false;
            }
            var re =/^[1-9]+[0-9]*]*$/  ;
            if(!((re.test(parseInt(phone))&&phone.length==11))){
                alert("11位正确的手机号码");
                return false;
            }
            var img=$("#img").val();
            $.ajax({
                ajax:"false",
                type: "POST",            //http请求方式
                url: "signDemo_1Service",    //服务器段url地址
                data: "MIname=" + cname+"&password="+cpassword+"&Sex="+csex+"&birthday="+years+"-"+yues+"-"+days+"&phonenb="+parseInt(phone)+"&indentity="+img,           //发送给服务器段的数据
                dataType: "xml",  //告诉JQuery返回的数据格式
                success: callback  //定义交互完成，并且服务器正确返回数据时调用的回调函数
            });

            function callback(data){
                alert("接收数据");
                //alert($(data).find("pass").text());
                //alert($(data).find("how").text());
                var pass=$(data).find("pass").text();
                var how=$(data).find("how").text();
                if(pass=="YES"){
                    alert($(data).find("how").text());
                    var urli="http://localhost:8080/sun/denglu";
                    //var urli="http://119.29.253.118:8080/denglu";
                    //alert(""+urli);
                    //window.location=urli;


                }else{
                    if(how=="连接数据库出错"){
                        alert($(data).find("how").text());

                    }
                    else{
                        alert($(data).find("how").text());


                    }

                }

            }
        }

    </script>
</head>
<body>
<div align="center">
    <h3>用户名</h3>
    <input type="text" id="userName" /><br>
    <h3>密码</h3>
    <input type="password" id="password" /><br>
    确认密码<br><input type="password" id="repassword" /><br>
    <h3>性别</h3>
    <form>
        男<input type="radio"  name="Sex" value="男" />
        女<input type="radio" name="Sex" value="女" />
    </form>
    <h3>生日</h3>
    <input type="text" id="birthyear" />年<br>
    <input type="text" id="birthyue" />月<br>
    <input type="text" id="birthday" />日<br>
    <h3>手机号码</h3>
    手机号码<input type="text" id="phonenb" />
    <br><img   alt="验证码 " src="/sun/ramdonImg.action" id="indentity" onload="btn.disabled=false; "/><br/>


    <input  type="button" value="换个图片" id="btn" onclick="reloadImage()">
    <input type="text" id="img">
    <br><input type="button" value="注册" onclick="verify()"/>
</div>
</body>
</html>
